package com.atguigu.tingshu.search.api;

import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.search.service.ItemService;
import com.atguigu.tingshu.vo.search.AlbumInfoIndexVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Tag(name = "专辑详情管理")
@RestController
@RequestMapping("api/search/albumInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class itemApiController {

	@Autowired
	private ItemService itemService;

	@PostMapping("/onAlbumEs/{albumId}")
	@Operation(summary = "上架专辑到es")
    public Result onAlbumInfos(@PathVariable("albumId") Long albumId){
		itemService.onAlbumInfos(albumId);
		return Result.ok();
	}

	@DeleteMapping("/offAlbumEs/{albumId}")
	@Operation(summary = "上架专辑到es")
	public Result offAlbumEs(@PathVariable("albumId") Long albumId){
		itemService.offAlbumEs(albumId);
		return Result.ok();
	}

	@PostMapping("/batch/onAlbumEs")
	@Operation(summary = "批量上架专辑到es")
	public Result onAlbumInfoList(){
		for (int i = 1; i < 1577; i++) {
			itemService.onAlbumInfos((long)i);

		}
		return Result.ok();
	}
	//Request URL: http://localhost:8500/api/search/albumInfo/214

	@GetMapping("/{albumId}")
	@Operation(summary = "获取专辑详细信息")
	public Result albumInfoDetails(@PathVariable(value = "albumId") Long albumId){
		Map<String,Object> result=itemService.albumInfoDetails(albumId);
		return Result.ok(result);
	}

	//http://localhost:8500/api/search/albumInfo/findRankingList/1/hotScore
	@GetMapping("/preHitRank")
	@Operation(summary = "排行榜数据的提前预热")
	public Result preHitRank(){
		itemService.preHitRank();
		return Result.ok();
	}
	//http://localhost:8500/api/search/albumInfo/findRankingList/1/hotScore
	@GetMapping("/findRankingList/{c1Id}/{dimension}")
	@Operation(summary = "排行榜数据")
	public Result findRankingList(@PathVariable(value = "c1Id") Long c1Id,
								  @PathVariable(value = "dimension") String  dimension){
		List<AlbumInfoIndexVo> albumInfoIndexVoList= itemService.findRankingList(c1Id,dimension);
		return Result.ok(albumInfoIndexVoList);
	}
}

